package com.lanling.redis.client.client;

import com.lanling.redis.client.connection.Connection;
import com.lanling.redis.client.protocol.Protocol;
import com.lanling.redis.client.util.SafeEncoder;


/**
 * @date ：Created in 2021/11/23 9:34
 * @description：api操作层
 * @author：lanling
 */
public class Client {

    Connection connection;

    public Client(String host, int port) {
        this.connection = new Connection(host, port);
    }

    public String set(String key, String value) {

        connection.sendCommand(Protocol.Command.SET, SafeEncoder.encode(key), SafeEncoder.encode(value));

        return connection.getStatusCodeReply();
    }

    public String get(String key) {

        connection.sendCommand(Protocol.Command.GET, SafeEncoder.encode(key));

        return connection.getBulkReply();
    }
}
